<?php
namespace app\common\model;

use app\extra\BaseModel;
use app\extra\DBCont;
use think\Exception;

class Advert extends BaseModel
{
    protected $insert = ['user_id', 'edit_user_id'];
    protected $update = ['edit_user_id'];
    public function setUserIdAttr()
    {
        return getUserID();
    }
    public function setEditUserIdAttr()
    {
        return getUserID();
    }
    public function getImageAttr($value, $data){
        if (empty($value)){
            $value = model('Member')->where('team_id', $data['id'])->value('image');
            if (empty($value)){
                return null;
            }
        }
        return [
            'key' => $value,
            'value' => showFileUrl($value)
        ];
    }
    public function setImageAttr($value){
        return serializeByArray($value, ',');
    }
    /**
     * 添加额外参数
     * @param $item
     */
    public function setAddedField(&$item){
        $item['user_desc'] = model('Admin')->getUserName($item['user_id']);
        $item['publish_user'] = model('Admin')->getUserName($item['edit_user_id']);
    }
}